// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

export component TestCase {
    width: 300px;
    height: 300px;

    in-out property <bool> popup-created;
    in-out property <int> click-count;
    in-out property <int> popup-selector: 0;

    default-popup := PopupWindow {
        width: parent.width;
        height: parent.height;
        Text {
            text: "I'm a default";
        }
        init => {
            root.popup-created = true;
        }        
    }

    self-closing-popup := PopupWindow {
        close-on-click: false;
        width: parent.width;
        height: parent.height;
        Text {
            text: "I'm a self-closing popup";
        }
        TouchArea {
            clicked => {
                self-closing-popup.close();
            }
        }
        init => {
            root.popup-created = true;
        }
    }

    never-closing-popup := PopupWindow {
        close-on-click: false;
        width: parent.width;
        height: parent.height;
        Text {
            text: "I'm a popup that never closes";
        }
        TouchArea {
            clicked => {
            }
        }
        init => {
            root.popup-created = true;
        }
    }

    TouchArea {
        clicked => {
            root.click-count = root.click-count + 1;
            if (root.popup-selector == 0) {
                root.popup-selector = 3;
                default-popup.show();
            } else if (root.popup-selector == 1) {
                root.popup-selector = 3;
                self-closing-popup.show();
            } else if (root.popup-selector == 2) {
                root.popup-selector = 3;
                never-closing-popup.show();
            }
        }
    }
}
/*

```rust
let instance = TestCase::new().unwrap();

assert_eq!(instance.get_click_count(), 0);
assert_eq!(instance.get_popup_created(), false);

instance.set_popup_selector(0);
instance.set_popup_created(false);
instance.set_click_count(0);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_click_count(), 1);
assert_eq!(instance.get_popup_created(), true);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_click_count(), 1);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_click_count(), 2);

instance.set_popup_selector(1);
instance.set_popup_created(false);
instance.set_click_count(0);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_click_count(), 1);
assert_eq!(instance.get_popup_created(), true);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_click_count(), 1);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_click_count(), 2);

instance.set_popup_selector(2);
instance.set_popup_created(false);
instance.set_click_count(0);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_click_count(), 1);
assert_eq!(instance.get_popup_created(), true);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_click_count(), 1);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_click_count(), 1);
```

```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;

assert_eq(instance.get_click_count(), 0);
assert_eq(instance.get_popup_created(), false);

instance.set_popup_selector(0);
instance.set_popup_created(false);
instance.set_click_count(0);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_click_count(), 1);
assert_eq(instance.get_popup_created(), true);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_click_count(), 1);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_click_count(), 2);

instance.set_popup_selector(1);
instance.set_popup_created(false);
instance.set_click_count(0);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_click_count(), 1);
assert_eq(instance.get_popup_created(), true);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_click_count(), 1);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_click_count(), 2);

instance.set_popup_selector(2);
instance.set_popup_created(false);
instance.set_click_count(0);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_click_count(), 1);
assert_eq(instance.get_popup_created(), true);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_click_count(), 1);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_click_count(), 1);
```

```disable-because-nodejs-runs-with-qt-and-send-mouse-click-wont-send-to-popup-qwindow
var instance = new slint.TestCase({});

assert.equal(instance.click_count, 0);
assert.equal(instance.popup_created, false);

instance.popup_selector = 0;
instance.popup_created = false;
instance.click_count = 0;
instance.send_mouse_click(5., 5.);
assert.equal(instance.click_count, 1);
assert.equal(instance.popup_created, true);
instance.send_mouse_click(5., 5.);
assert.equal(instance.click_count, 1);
instance.send_mouse_click(5., 5.);
assert.equal(instance.click_count, 2);

instance.popup_selector = 1;
instance.popup_created = false;
instance.click_count = 0;
instance.send_mouse_click(5., 5.);
assert.equal(instance.click_count, 1);
assert.equal(instance.popup_created, true);
instance.send_mouse_click(5., 5.);
assert.equal(instance.click_count, 1);
instance.send_mouse_click(5., 5.);
assert.equal(instance.click_count, 2);

instance.popup_selector = 2;
instance.popup_created = false;
instance.click_count = 0;
instance.send_mouse_click(5., 5.);
assert.equal(instance.click_count, 1);
assert.equal(instance.popup_created, true);
instance.send_mouse_click(5., 5.);
assert.equal(instance.click_count, 1);
instance.send_mouse_click(5., 5.);
assert.equal(instance.click_count, 1);
```

*/
